package com.example.dynamic.jdk;

import com.example.dynamic.aspect.LogForService;

import java.lang.reflect.Proxy;

public class JdkProxy {
    public Object getProxy(Object target) {
        return Proxy.newProxyInstance(
                target.getClass().getClassLoader(),
                target.getClass().getInterfaces(),
                (proxy, method, args) -> {
                    LogForService log = new LogForService();
                    log.before(method.getName());
                    Object o = method.invoke(target, args);
                    log.after(method.getName());
                    return o;
                });
    }
}
